class Solution(object):
    def shortestToChar(self, s, c):
        """
        :type s: str
        :type c: str
        :rtype: List[int]
        """
        n = len(s)
        out = [-1] * n
        now = set()
        for i in range(n):
            if s[i] == c:
                now.add(i)
                out[i] = 0
        dist = 0
        while now:
            dist += 1
            next_set = set()
            for x in now:
                for ux in [x - 1, x + 1]:
                    if 0 <= ux < n and out[ux] == -1:
                        out[ux] = dist
                        next_set.add(ux)
            now = next_set

        return out


data = Solution()
s = "loveleetcode"
c = "e"
print(data.shortestToChar(s, c))
s = "aaab"
c = "b"
print(data.shortestToChar(s, c))